/**
 * @license Modifica e usa come vuoi
 *
 * Creato da TurboLab.it - 01/01/2014 (buon anno!)
 */
CKEDITOR.dialog.add( 'githubDialog', function( editor ) {

    return {
        title: 'Github',
        minWidth: 400,
        minHeight: 75,
        contents: [
            {
                id: 'tab-basic',
                label: 'Basic Settings',
                elements: [
                    {
                        type: 'text',
                        id: 'githubUrl',
                        label: 'Github 連結'
                    }
                ]
            }
        ],
        onOk: function() {
            var dialog = this;
            var url = dialog.getValueOf( 'tab-basic', 'githubUrl').trim();
            var urls = url.split("/");
            
            
            if(urls==null || urls[2]!='gist.github.com'){
				alert("請輸入有效的Github連結");
				return false;
			}
            
            var str = "<span>";
            if(urls[3]=='clonn')
            	str += "<script src='"+url+".js'></script>";
            else
            	str += "<script src='https://gist.github.com/clonn/"+urls[3].split(".")[0]+".js'></script>";
            str += "Github Code: <a href='"+url+"'>"+url;
            str += "</a></span><br>";
            editor.insertHtml(str);
        }
    };
});